import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:smart_devices/icons/flutter_icons.dart';
import 'package:smart_devices/routes/index.dart';
import 'package:smart_devices/utils/colors.dart';
import 'package:smart_devices/utils/styles.dart';
import 'package:smart_devices/utils/tools.dart';

class DeviceController extends GetxController {
  RxInt run = RxInt(32);

  RxInt fault = RxInt(3);

  RxInt stop = RxInt(5);

  RxInt invalidated = RxInt(10);

  RxInt total = RxInt(30);

  @override
  void onClose() {
    super.onClose();
    Get.delete();
  }
}

class DevicePage extends GetView<DeviceController> {
  const DevicePage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<DeviceController>(
      builder: (_) {
        return Scaffold(
          backgroundColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF6f6),
          appBar: AppBar(
            automaticallyImplyLeading: false,
            title: Text(
              '设备',
              style: StylesUtils.customTextStyle(fontSize: 16, fontWeight: FontWeight.w700),
            ),
            centerTitle: true,
            backgroundColor: ColorsUtils.parseColorFromHexString(ColorsUtils.color0052),
          ),
          body: SingleChildScrollView(
            padding: const EdgeInsets.all(15),
            child: Column(
              children: [
                Container(
                  decoration: BoxDecoration(
                      color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFfff)),
                  child: ListBody(
                    children: [
                      Container(
                        height: 40,
                        alignment: Alignment.centerLeft,
                        padding: const EdgeInsets.symmetric(horizontal: 15),
                        child: Text(
                          '设备状态',
                          style: StylesUtils.customTextStyle(
                              fontSize: 15,
                              color: ColorsUtils.color1c24,
                              fontWeight: FontWeight.w700),
                        ),
                      ),
                      GridView(
                        shrinkWrap: true,
                        physics: const NeverScrollableScrollPhysics(),
                        padding: const EdgeInsets.symmetric(horizontal: 15),
                        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                          crossAxisCount: 4,
                        ),
                        children: [
                          Column(
                            children: [
                              Container(
                                height: 25,
                                alignment: Alignment.center,
                                child: ObxValue(
                                    (data) => Text(
                                          '${data.value}',
                                          style: StylesUtils.customTextStyle(
                                              fontWeight: FontWeight.w700,
                                              fontSize: 16,
                                              color: ColorsUtils.color3333),
                                        ),
                                    controller.run),
                              ),
                              Container(
                                height: 25,
                                alignment: Alignment.center,
                                child: Text(
                                  '正常运行',
                                  style: StylesUtils.customTextStyle(color: ColorsUtils.color9999),
                                ),
                              )
                            ],
                          ),
                          Column(
                            children: [
                              Container(
                                height: 25,
                                alignment: Alignment.center,
                                child: Obx(() => Text(
                                      '${controller.fault.value}',
                                      style: StylesUtils.customTextStyle(
                                          fontWeight: FontWeight.w700,
                                          fontSize: 16,
                                          color: ColorsUtils.colorD900),
                                    )),
                              ),
                              Container(
                                height: 25,
                                alignment: Alignment.center,
                                child: Text(
                                  '故障',
                                  style: StylesUtils.customTextStyle(color: ColorsUtils.colorD900),
                                ),
                              )
                            ],
                          ),
                          Column(
                            children: [
                              Container(
                                height: 25,
                                alignment: Alignment.center,
                                child: Obx(() => Text(
                                      '${controller.stop.value}',
                                      style: StylesUtils.customTextStyle(
                                          fontWeight: FontWeight.w700,
                                          fontSize: 16,
                                          color: ColorsUtils.color3333),
                                    )),
                              ),
                              Container(
                                height: 25,
                                alignment: Alignment.center,
                                child: Text(
                                  '停役',
                                  style: StylesUtils.customTextStyle(color: ColorsUtils.color9999),
                                ),
                              )
                            ],
                          ),
                          Column(
                            children: [
                              Container(
                                  height: 25,
                                  alignment: Alignment.center,
                                  child: Obx(() => Text(
                                        '${controller.invalidated.value}',
                                        style: StylesUtils.customTextStyle(
                                            fontWeight: FontWeight.w700,
                                            fontSize: 16,
                                            color: ColorsUtils.color3333),
                                      ))),
                              Container(
                                height: 25,
                                alignment: Alignment.center,
                                child: Text(
                                  '报废',
                                  style: StylesUtils.customTextStyle(color: ColorsUtils.color9999),
                                ),
                              )
                            ],
                          ),
                        ],
                      )
                    ],
                  ),
                ),
                Container(
                  margin: const EdgeInsets.only(top: 10),
                  decoration: BoxDecoration(
                      color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFfff)),
                  child: ListBody(
                    children: [
                      SizedBox(
                        height: 50,
                        child: Row(
                          children: [
                            Container(
                              width: 50,
                              alignment: Alignment.center,
                              child: ToolsUtils.assetImageSvg('u48771.svg', width: 20, height: 20),
                            ),
                            Expanded(
                                child: Container(
                              alignment: Alignment.centerLeft,
                              child: Wrap(
                                spacing: 40,
                                children: [
                                  Text(
                                    '设备档案',
                                    style:
                                        StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                                  ),
                                  Obx(() => Text(
                                        '设备总数${controller.total.value}台',
                                        style: StylesUtils.customTextStyle(
                                            color: ColorsUtils.color9999),
                                      ))
                                ],
                              ),
                            )),
                            Container(
                                width: 40,
                                alignment: Alignment.center,
                                child: IconButton(
                                  icon: Icon(
                                    AntdIcons.right,
                                    color:
                                        ColorsUtils.parseColorFromHexString(ColorsUtils.color9999),
                                    size: 15,
                                  ),
                                  onPressed: () {
                                    Get.toNamed(Routes.deviceList,
                                        arguments: controller.total.value);
                                  },
                                ))
                          ],
                        ),
                      ),
                      SizedBox(
                        height: 50,
                        child: Row(
                          children: [
                            Container(
                              width: 50,
                              alignment: Alignment.center,
                              child: ToolsUtils.assetImageSvg('u48780.svg', width: 20, height: 20),
                            ),
                            Expanded(
                                child: Container(
                              alignment: Alignment.centerLeft,
                              child: Wrap(
                                spacing: 40,
                                children: [
                                  Text(
                                    '设备盘点',
                                    style:
                                        StylesUtils.customTextStyle(color: ColorsUtils.color3333),
                                  ),
                                ],
                              ),
                            )),
                            InkWell(onTap: () {
                              Get.toNamed(Routes.deviceInventoryList);
                            }, child: Container(
                              width: 40,
                              alignment: Alignment.center,
                              child: Icon(
                                AntdIcons.right,
                                color: ColorsUtils.parseColorFromHexString(ColorsUtils.color9999),
                                size: 15,
                              ),
                            ),)
                          ],
                        ),
                      ),
                    ],
                  ),
                )
              ],
            ),
          ),
        );
      },
      init: Get.put(DeviceController()),
    );
  }
}
